package com.ruoyi.wx.service.impl;


import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.utils.WxConfig;
import com.ruoyi.utils.WxUrl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.ruoyi.wx.service.WxService;

/**
 * @Description: TODO
 * @Create by: jacob
 * @Date: 2025/2/3
 * 遇见未来的自己
 */
@Service
public class WxServiceImpl implements WxService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public JSONObject getLoginAccessToken(String code) {
        String url = WxUrl.ACCESS_TOKEN_BY_CODE_URL;
        url = url.replace("APPID", WxConfig.SP_APPID).replace("APPSECRET",WxConfig.SP_SECRET).replace("CODE",code);
        String resStr = HttpUtils.sendGet(url);
        return JSONObject.parseObject(resStr);
    }

    @Override
    public JSONObject getLoginUserInfo(String accessToken, String openid) {
        String userinfoUrl = WxUrl.WX_USER_INFO_URL;
        userinfoUrl = userinfoUrl.replace("ACCESS_TOKEN",accessToken).replace("OPENID",openid);
        String userinfoStr = HttpUtils.sendGet(userinfoUrl);
        return JSONObject.parseObject(userinfoStr);
    }
}
